import { NodeStatus } from "../../common/Enum"
/** 节点 */
export default abstract class BTNode {
    private _status: NodeStatus = NodeStatus.Inactive

    set status(newStatus) {
        this._status = newStatus
    }

    get status() {
        return this._status
    }

    run() {
        if (this.status === NodeStatus.Inactive) {
            this.onStart()
        }

        const res = this.onUpdate()
        if (res !== NodeStatus.Running) {
            this.onEnd();
        }
        return res
    }

    onStart() {
        this.status = NodeStatus.Running
    }

    onUpdate() {

        return NodeStatus.Success
    }

    onEnd() {
        this.status = NodeStatus.Inactive
    }
}